package com.gjy.design.decorator.s3;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-11-10 10:30:46
 */
public class Filters {

    private Filters() {
    }

    public static SmartFilter trim() {
        return s -> s.trim();
    }

    public static SmartFilter removeControlChars() {
        return s -> s.replaceAll("[\\p{C}]", "");
    }

    public static SmartFilter lengthLimit(int max) {
        return s -> s.length() > max ? s.substring(0, max) : s;
    }

    public static SmartFilter escapeHtml() {
        return s -> s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
                .replace("\"", "&quot;").replace("'", "&#39;");
    }

    // 运行时参数化装饰器
    public static SmartFilter normalizeEmoji(boolean enable) {
        return enable ? s -> s.replaceAll("[\\p{So}]", "") : s -> s;
    }

}
